package com.example.demo.controller;



import com.example.demo.model.PsPointN;
import com.example.demo.repository.PointRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class PointController {

    @Autowired
    private PointRepository pointRepository;


    @RequestMapping("/hello")
    public String hello() {
        return "hello WebGIS";
    }

    @GetMapping("/getPoint")
    public List<PsPointN> getPoint(@RequestParam Double coorx, @RequestParam Double coory, @RequestParam Integer distance) {
        List<PsPointN> pointList = pointRepository.getPoint(coorx, coory, distance);
        return pointList;
    }

    @GetMapping("/getPointByExtent")
    public List<PsPointN> getPointByExtent(@RequestParam Double minx, @RequestParam Double miny, @RequestParam Double maxx, @RequestParam Double maxy) {
        List<PsPointN> pointList = pointRepository.getPointByExtent(minx, miny, maxx, maxy);
        return pointList;
    }

    @GetMapping("/getPointByWkt")
    public Map<String, Object> getPointByWkt(@RequestParam String wkt,@RequestParam Integer page) {
        List<PsPointN> pointList = pointRepository.getPointByWkt(wkt,page);
        Integer count = pointRepository.getCountByWkt(wkt);

        Map<String, Object> map = new HashMap<>();
        map.put("count",count);
        map.put("data",pointList);

        return map;
    }

    @PostMapping("/updatePoint")
    public Boolean addUser(@RequestParam(value = "survey_no", required = true) String survey_no,@RequestParam(value = "geom", required = true) String geom) {
        return pointRepository.updateGeom(survey_no,geom);
    }




}

